import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:macnov/common/indicator.dart';
import 'package:macnov/role_owner/wallet/components/summary.dart';
import 'package:macnov/role_owner/wallet/pcardscene.dart';
import 'package:macnov/role_owner/wallet/vcardscene.dart';
import 'package:macnov/stores/wallet.dart';
import 'package:macnov/utils/colorUtil.dart';
import 'package:macnov/utils/dateutil.dart';

class HeaderItem {
  final String labelTitle;
  HeaderItem(this.labelTitle);
}

final List<HeaderItem> _allPages = <HeaderItem>[
  new HeaderItem("Summary"),
  new HeaderItem("Physical cards"),
  new HeaderItem("Virtual cards"),
];

class Wallet extends StatefulWidget {
  @override
  _WalletState createState() => _WalletState();
}

class _WalletState extends State<Wallet> with AutomaticKeepAliveClientMixin {
  Widget _renderTabs() {
    return Material(
      color: Colors.white,
      child: new TabBar(
        isScrollable: true,
        indicator: YLStatisticsIndictor(),
        unselectedLabelColor: ColorsUtil.hexColor(0x8F909A),
        labelColor: ColorsUtil.hexColor(0x000000),
        tabs: _allPages
            .map((HeaderItem page) => new Tab(
                    child: Text(
                  page.labelTitle,
                )))
            .toList(),
      ),
    );
  }

  Widget _renderBody() {
    return new TabBarView(
      children: <Widget>[
        new Summary(),
        new PhysicalCardScene(),
        new VirtualCardScene(),
      ],
    );
  }

  Widget _renderHeader() {
    return Row(
      children: <Widget>[
        Expanded(
          child: Text('Cards',
              style: TextStyle(
                  fontSize: 25.0,
                  color: ColorsUtil.hexColor(0x282828),
                  fontWeight: FontWeight.w700)),
        ),
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return new DefaultTabController(
        length: _allPages.length,
        child: new Scaffold(
          appBar: new AppBar(
            brightness: Brightness.light,
            backgroundColor: Colors.white,
            elevation: 0,
            actions: <Widget>[
              Padding(
                padding: const EdgeInsets.only(right: 0.0),
                child: new FlatButton(
                  child: new Text(
                    '+ CARD',
                    style: TextStyle(color: Colors.blue),
                  ),
                  onPressed: () {
                    Navigator.pushNamed(context, "/owner/newcard");
                  },
                ),
              ),
            ],
            title: _renderHeader(),
          ),
          body: Column(
            children: <Widget>[
              Container(
                color: Colors.white,
                child: _renderTabs(),
                height: 30,
                width: MediaQuery.of(context).size.width,
              ),
              Expanded(
                child: _renderBody(),
              )
            ],
          ),
        ));
  }

  @override
  void initState() {
    super.initState();
    walletStore.loadOwnerCompanyAccountInfo();
    walletStore.getCreditInfo();

    walletStore.getMonthlyPaymentCategory(DateTime.now().month);
    walletStore.getMonthlyPayment(DateTime.now().month);
  }

  @override
  bool get wantKeepAlive => true;
}
